package com.fairisanddog.controller;

import com.alibaba.fastjson.JSON;

import com.fairisanddog.entity.Books;
import com.fairisanddog.service.BooksService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/book")
public class BooksController {
    @Autowired
    @Qualifier("BooksServiceImpl")
    private BooksService booksService;


    @RequestMapping("/findAllBooks")
    @ResponseBody
    public String QueryAllBooks(){
        List<Books> books = booksService.queryAllBooks();
        if (books!=null){
            String booksJson = JSON.toJSONString(books);
            return booksJson;
        }else {
            return "no";
        }
    }

    @RequestMapping("/findType")
    @ResponseBody
    public String queryBookByType(@Param("btype") String btype){
       List<Books> books = booksService.queryBookByType(btype);
       return JSON.toJSONString(books);
    }
}
